package com.demo.chapter3lambda;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.Function;

import com.demo.domain.Apple;

/**方法引用，3种形式：
 * 1、(args) -> ClassName.staticMethod(args)
 * ClassName::staticMethod
 * 2、(arg0, rest) -> arg0.instanceMethod(rest)
 * ClassName::instanceMethod，arg0是ClassName类型的
 * 3、(args) -> expr.instanceMethod(args)
 * expr::instanceMethod，调用一个已经存在的外部对象中的方法
 * @author dell
 *
 */
public class MethodReference {

	public void demo(){
		List<String> str = Arrays.asList("a", "b", "c", "d");
		str.sort((x, y) -> x.compareToIgnoreCase(y));
		str.sort(String::compareToIgnoreCase);

		Function<String, Integer> stringToInteger = (String s) -> Integer.parseInt(s);
		Function<String, Integer> stringToInteger2 = Integer::parseInt;

		BiPredicate<List<String>, String> contains = (list, element) -> list.contains(element);
		BiPredicate<List<String>, String> contains2 = List::contains;
	}

}
